<?php
/**
 * 抽奖结果页
 */
namespace backend\controllers;

use bc\controller\BackendController;
use yii;
use bc\model\h5\PrizeModel;
use bc\util\backend\Page;

class PrizeController extends BackendController
{
	
	/**
	 * 列表页
	 */
	public function actionIndex()
	{
		$prize_type = $this->get('prize_type', '');
		$name = $this->get('name');
		
		$model = new PrizeModel();
		$params = ' 1 = 1';
		
		if($prize_type)
		{
			$params .= ' AND `prize_type` = "' . $prize_type . '"';
		}
		
		if($name)
		{
			$params .= ' AND `nickname` = "' . $name . '"';
		}
		
		
		$page = $this->get('page', 1);
		$model->sort = 'prize_id DESC';
		$list = $model->getList($params, $page, self::PAGE_SIZE);
		
		$total = $model->getTotal($params);
		
		$pagination = new Page($total, self::PAGE_SIZE);
		
		$view['list'] = $list;
		$view['pagination'] = $pagination;
		$view['name'] = $name;
		$view['prize_type'] = $prize_type;
		return $this->render('index', $view);
	}
	

	/**
	 * 编辑
	 */
	public function actionEdit()
	{
		$id = $this->get('id');
		
		if(!$id)
			$this->redirect('/');
		
		$model = new PrizeModel();
		$row = $model->getRowById($id);
		
		$view['row'] = $row;
		
		return $this->render('edit', $view);
	}
	
	
}

